<?php
namespace Web\Controller;
use Think\Controller;

class CommonController extends Controller {
    protected $layout = false;

    public function __construct() {
        parent::__construct();
        C('DEFAULT_THEME','default');
        set_exception_handler(array($this,'exception_error'));

        $sid = site_cache('sid');

        if(!$sid) {
            header("HTTP/1.1 404 not found");
            exit();
        }

        if(!site_cache('status')) {
            exit('网站不存在或已经下线');
        }

        $this->assign(array(
            'controller_name'   =>  strtolower(CONTROLLER_NAME),
            'action_name'        =>  strtolower(ACTION_NAME),
        ));
    }

    protected function success($message,$redirect_url = '') {
        if(!$redirect_url) $redirect_url = $_SERVER['HTTP_REFERER'];
        redirect($redirect_url);exit();
    }

    protected function error($message,$redirect_url = '') {
        if(!$redirect_url) $redirect_url = $_SERVER['HTTP_REFERER'];
        redirect($redirect_url);exit();
    }
    
    public function exception_error(\Exception $e) {
        if(IS_AJAX) {
            $this->errorAjax($e->getMessage());
        }else{
            $this->error($e->getMessage());
        }
    }
}
?>
